package com.ylx.demo.sender;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class MyKafkaMessageSender {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    /**
     * 发送消息到指定的topic主题
     *
     * @param topicName      主题名称
     * @param messagePayload 消息主体信息
     */
    public void sendMessage(String topicName, Object messagePayload) {
        //发送消息到kafka
        kafkaTemplate.send(topicName, messagePayload);
    }

}
